
/*
Copyright 2009 Peter Ekler, Akos Ludanyi, Budapest University of Technology and Economics, Department of Automation and Applied Informatics, Applied Mobile Research Group (AMORG) http://amorg.aut.bme.hu

This file is part of MobTorrent.

MobTorrent is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

MobTorrent is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with MobTorrent.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ui;

import TorrentEngine.MTStringFormatter;
import TorrentEngine.MTTorrent;
import data.LocalizationSupport;
import data.MTPreferences;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;

/**
 *
 * @author Tyrael
 */
public class MTFormProperties extends Form implements CommandListener
{
    public static final int ScreenID = 4;

    private MTUIManager uiManager;
    private Command command_Back;
    private StringItem stringItemTorrentFilePath;
    private StringItem stringItemTargetPath;
    private StringItem stringItemSize;
    private StringItem stringItemAnnounceURL;
    private StringItem stringItemPieceLength;
    private StringItem stringItemPieceNum;
    private StringItem stringItemInfoHash;

    public MTFormProperties(String aTitle, MTUIManager aUIManager)
    {
        super(aTitle);
        uiManager = aUIManager;

        stringItemTorrentFilePath = new StringItem(
            LocalizationSupport.getMessage("label_torrentFilePath")+":","");
        append(stringItemTorrentFilePath);

        stringItemTargetPath = new StringItem(
            LocalizationSupport.getMessage("label_targetPath")+":","");
        append(stringItemTargetPath);

        stringItemSize = new StringItem(
            LocalizationSupport.getMessage("label_size")+":","");
        append(stringItemSize);

        stringItemAnnounceURL = new StringItem(
            LocalizationSupport.getMessage("label_announceURL")+":","");
        append(stringItemAnnounceURL);

        stringItemPieceLength = new StringItem(
            LocalizationSupport.getMessage("label_pieceLength")+":","");
        append(stringItemPieceLength);

        stringItemPieceNum = new StringItem(
            LocalizationSupport.getMessage("label_pieceNum")+":","");
        append(stringItemPieceNum);

        stringItemInfoHash = new StringItem(
            LocalizationSupport.getMessage("label_infoHash")+":","");
        append(stringItemInfoHash);


        command_Back = new Command(LocalizationSupport.getMessage("command_back"), Command.BACK, 0);
        addCommand(command_Back);
        setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d)
    {
        if (c == command_Back)
        {
            uiManager.showScreen(MTListTorrents.ScreenID);
        }
    }

    public void initialize(MTTorrent aTorrent)
    {
        setTitle(aTorrent.getTorrentNameWithoutPath());

        stringItemTorrentFilePath.setText(aTorrent.getTorrentFilePath());
        stringItemTargetPath.setText(MTPreferences.DownloadFolder);
        stringItemSize.setText(MTStringFormatter.getFormattedFileLength(aTorrent.size()));
        stringItemAnnounceURL.setText(aTorrent.getAnnounce());
        stringItemPieceLength.setText(MTStringFormatter.getFormattedFileLength(aTorrent.getPieceLength()));
        stringItemPieceNum.setText(""+aTorrent.pieceCount());
        stringItemInfoHash.setText(aTorrent.getInfoHash());
    }

}

